home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / BugBug / bugbug.jar / bugbug / YopparaiCanvas.class (.txt) < prev   
Encoding:
Java Class File  |  2001-07-25  |  7.1 KB  |  408 lines

  1. package bugbug;
  2.  
  3. import javax.microedition.lcdui.Canvas;
  4. import javax.microedition.lcdui.Form;
  5. import javax.microedition.lcdui.Graphics;
  6. import javax.microedition.lcdui.Image;
  7.  
  8. class YopparaiCanvas extends Canvas implements Runnable {
  9.    // $FF: renamed from: I bugbug.BugBug
  10.    private BugBug field_0;
  11.    // $FF: renamed from: Z javax.microedition.lcdui.Form
  12.    private Form field_1;
  13.    private static String Code;
  14.    private static int init;
  15.    private static int keyReleased;
  16.    public static int proc;
  17.    private static int keyPressed;
  18.    private static Graphics keyRepeated;
  19.    public static int mode;
  20.    private static int move;
  21.    private static int paint;
  22.    private static int run;
  23.    private static int append;
  24.    private static int toString;
  25.    private static int createImage = 51;
  26.    private static int getWidth;
  27.    private static int getHeight;
  28.    private static int[] out;
  29.    private static int[] println;
  30.    public static boolean thread_state;
  31.    private static int getGraphics;
  32.    private static int drawImage;
  33.    private static int setColor;
  34.    private static int fillRect;
  35.    // $FF: renamed from: gc int
  36.    private static int field_2;
  37.    private static int getGameAction;
  38.    private static int rand;
  39.    private static int abs;
  40.    private static int drawLine;
  41.    private static int drawString;
  42.    private static int setLocalHighscore;
  43.    private static int saveHighscore;
  44.    private static int[] checkInetHighscore;
  45.    private static int[] repaint;
  46.    private static int[] yield;
  47.    private static int sleep;
  48.    // $FF: renamed from: A javax.microedition.lcdui.Image[]
  49.    private static Image[] field_3;
  50.    // $FF: renamed from: B javax.microedition.lcdui.Image[]
  51.    private static Image[] field_4;
  52.    // $FF: renamed from: C javax.microedition.lcdui.Image
  53.    private static Image field_5;
  54.    // $FF: renamed from: D javax.microedition.lcdui.Image
  55.    private static Image field_6;
  56.    // $FF: renamed from: E javax.microedition.lcdui.Graphics
  57.    private static Graphics field_7;
  58.    // $FF: renamed from: F javax.microedition.lcdui.Graphics
  59.    private static Graphics field_8;
  60.    // $FF: renamed from: G boolean
  61.    private boolean field_9 = false;
  62.    // $FF: renamed from: H javax.microedition.lcdui.Image[]
  63.    private static Image[] field_10;
  64.    // $FF: renamed from: J javax.microedition.lcdui.Image[]
  65.    private static Image[] field_11;
  66.  
  67.    public YopparaiCanvas(BugBug var1) {
  68.       this.field_0 = var1;
  69.  
  70.       try {
  71.          for(getWidth = 0; getWidth < 10; ++getWidth) {
  72.             field_10[getWidth] = Image.createImage("/bugbug/" + getWidth + ".png");
  73.             field_11[getWidth] = Image.createImage(field_10[getWidth].getWidth(), field_10[getWidth].getHeight());
  74.          }
  75.       } catch (Exception var4) {
  76.          System.out.println("Exception: " + var4);
  77.       }
  78.  
  79.       this.init();
  80.  
  81.       try {
  82.          field_5 = Image.createImage(((Canvas)this).getWidth() + 1, ((Canvas)this).getHeight());
  83.          field_6 = Image.createImage(((Canvas)this).getWidth() + 1, ((Canvas)this).getHeight());
  84.          field_7 = field_5.getGraphics();
  85.          field_8 = field_6.getGraphics();
  86.          field_8.drawImage(field_10[6], 0, 0, 20);
  87.          field_8.drawImage(field_10[6], field_10[6].getWidth(), 0, 20);
  88.          field_7.drawImage(field_10[6], 0, 0, 20);
  89.          field_7.drawImage(field_10[6], field_10[6].getWidth(), 0, 20);
  90.          field_8.drawImage(field_10[7], 0, field_10[6].getHeight() + 6, 20);
  91.          field_8.drawImage(field_10[7], field_10[6].getWidth(), field_10[6].getHeight() + 6, 20);
  92.          field_7.drawImage(field_10[7], 0, field_10[6].getHeight() + 6, 20);
  93.          field_7.drawImage(field_10[7], field_10[6].getWidth(), field_10[6].getHeight() + 6, 20);
  94.          field_8.setColor(0);
  95.          field_8.fillRect(0, (75 - toString) / 2 + 4 + 10, ((Canvas)this).getWidth(), toString - 10);
  96.       } catch (Exception var3) {
  97.          System.out.println("Exception: " + var3);
  98.       }
  99.  
  100.    }
  101.  
  102.    public void init() {
  103.       this.field_9 = false;
  104.       System.gc();
  105.       mode = 0;
  106.       Code = "";
  107.       proc = 0;
  108.       keyReleased = 0;
  109.       init = 20;
  110.       keyPressed = 0;
  111.       drawImage = 0;
  112.       setColor = 0;
  113.       fillRect = 0;
  114.       abs = 0;
  115.       rand = 1;
  116.       drawLine = 1;
  117.       move = 0;
  118.       paint = 15;
  119.       run = 50;
  120.       toString = 65;
  121.  
  122.       try {
  123.          field_8.setColor(255, 255, 255);
  124.          field_8.fillRect(0, 0, ((Canvas)this).getWidth() + 1, ((Canvas)this).getHeight());
  125.          field_7.setColor(255, 255, 255);
  126.          field_7.fillRect(0, 0, ((Canvas)this).getWidth() + 1, ((Canvas)this).getHeight());
  127.          field_8.setColor(0);
  128.          field_8.drawImage(field_10[6], 0, 0, 20);
  129.          field_8.drawImage(field_10[6], field_10[6].getWidth(), 0, 20);
  130.          field_7.drawImage(field_10[6], 0, 0, 20);
  131.          field_7.drawImage(field_10[6], field_10[6].getWidth(), 0, 20);
  132.          field_8.drawImage(field_10[7], 0, field_10[6].getHeight() + 6, 20);
  133.          field_8.drawImage(field_10[7], field_10[6].getWidth(), field_10[6].getHeight() + 6, 20);
  134.          field_7.drawImage(field_10[7], 0, field_10[6].getHeight() + 6, 20);
  135.          field_7.drawImage(field_10[7], field_10[6].getWidth(), field_10[6].getHeight() + 6, 20);
  136.          field_8.fillRect(0, (75 - toString) / 2 + 4 + 10, ((Canvas)this).getWidth(), toString - 10);
  137.       } catch (Exception var2) {
  138.       }
  139.  
  140.       for(getWidth = 0; getWidth < createImage; ++getWidth) {
  141.          out[getWidth] = (75 - toString) / 2 + 4;
  142.          println[getWidth] = out[getWidth] + toString;
  143.       }
  144.  
  145.       append = 0;
  146.  
  147.       for(getWidth = 0; getWidth < saveHighscore; ++getWidth) {
  148.          yield[getWidth] = 0;
  149.       }
  150.  
  151.       thread_state = true;
  152.    }
  153.  
  154.    public void keyReleased(int var1) {
  155.       if (proc == 1) {
  156.          int var2 = ((Canvas)this).getGameAction(var1);
  157.          if (var2 == 1) {
  158.             keyPressed = 0;
  159.          }
  160.       }
  161.  
  162.    }
  163.  
  164.    public void keyPressed(int var1) {
  165.       if (thread_state) {
  166.          if (proc == 0) {
  167.             proc = 1;
  168.             fillRect = 0;
  169.          } else if (proc == 1) {
  170.             int var2 = ((Canvas)this).getGameAction(var1);
  171.             if (var2 == 1) {
  172.                keyPressed = 1;
  173.             }
  174.          }
  175.       }
  176.  
  177.    }
  178.  
  179.    public void keyRepeated(int var1) {
  180.       if (proc == 1) {
  181.          int var2 = ((Canvas)this).getGameAction(var1);
  182.          if (var2 == 1) {
  183.             this.keyPressed(var1);
  184.          }
  185.       }
  186.  
  187.    }
  188.  
  189.    public void move() {
  190.       if (proc == 1) {
  191.          init += keyReleased;
  192.          if (keyPressed != 0) {
  193.             keyReleased -= 2;
  194.          }
  195.  
  196.          ++keyReleased;
  197.       }
  198.  
  199.    }
  200.  
  201.    public void paint(Graphics var1) {
  202.       switch (proc) {
  203.          case 0:
  204.             var1.setColor(0);
  205.             var1.fillRect(0, 0, ((Canvas)this).getWidth(), ((Canvas)this).getHeight());
  206.             var1.drawImage(field_10[8], ((Canvas)this).getWidth() / 2, 15, 17);
  207.             var1.drawImage(field_10[9], ((Canvas)this).getWidth() / 2, 60, 17);
  208.             var1.setColor(0);
  209.             break;
  210.          case 1:
  211.             move = (move + 1) % createImage;
  212.             paint = (paint + 1) % createImage;
  213.             run = (run + 1) % createImage;
  214.             if (move == 0) {
  215.                drawLine = (drawLine + 1) % 2;
  216.                if (drawLine == 0) {
  217.                   field_8.setColor(255, 255, 255);
  218.                   field_8.fillRect(0, 0, ((Canvas)this).getWidth() + 1, ((Canvas)this).getHeight());
  219.                   field_8.drawImage(field_10[6], 0, 0, 20);
  220.                   field_8.drawImage(field_10[6], field_10[6].getWidth(), 0, 20);
  221.                   field_8.drawImage(field_10[7], 0, field_10[6].getHeight() + 6, 20);
  222.                   field_8.drawImage(field_10[7], field_10[6].getWidth(), field_10[6].getHeight() + 6, 20);
  223.                } else {
  224.                   field_7.setColor(255, 255, 255);
  225.                   field_7.fillRect(0, 0, ((Canvas)this).getWidth() + 1, ((Canvas)this).getHeight());
  226.                   field_7.drawImage(field_10[6], 0, 0, 20);
  227.                   field_7.drawImage(field_10[6], field_10[6].getWidth(), 0, 20);
  228.                   field_7.drawImage(field_10[7], 0, field_10[6].getHeight() + 6, 20);
  229.                   field_7.drawImage(field_10[7], field_10[6].getWidth(), field_10[6].getHeight() + 6, 20);
  230.                }
  231.             }
  232.  
  233.             getGraphics = (short)(Rand.rand() % 5) - out[(run - 1 + createImage) % createImage] / ((75 - toString) / 5);
  234.             append += getGraphics;
  235.             if (append > 3 + rand % 20 / 4) {
  236.                --append;
  237.             } else if (append < -3 - rand % 20 / 4) {
  238.                ++append;
  239.             }
  240.  
  241.             if (out[(run - 1 + createImage) % createImage] < 0) {
  242.                append = Math.abs(append);
  243.             } else if (out[(run - 1 + createImage) % createImage] > 75 - toString) {
  244.                append = -Math.abs(append);
  245.             }
  246.  
  247.             out[run] = out[(run - 1 + createImage) % createImage] + append / 2;
  248.             println[run] = out[run] + toString;
  249.             if (move == 0) {
  250.                if (drawLine == 0) {
  251.                   field_7.drawLine(((Canvas)this).getWidth() - 1, out[50] + 10, ((Canvas)this).getWidth() - 1, println[50]);
  252.                } else {
  253.                   field_8.drawLine(((Canvas)this).getWidth() - 1, out[50] + 10, ((Canvas)this).getWidth() - 1, println[50]);
  254.                }
  255.             }
  256.  
  257.             field_8.setColor(0);
  258.             field_7.setColor(0);
  259.             if (drawLine == 0) {
  260.                if (move != 0) {
  261.                   field_8.drawLine(2 * run + 1, out[run % createImage] + 10, 2 * run + 1, println[run % createImage]);
  262.                   field_8.drawLine(2 * run, (out[run % createImage] + out[(run - 1 + createImage) % createImage]) / 2 + 10, 2 * run, (println[run % createImage] + println[(run - 1 + createImage) % createImage]) / 2);
  263.                }
  264.             } else if (move != 0) {
  265.                field_7.drawLine(2 * run + 1, out[run % createImage] + 10, 2 * run + 1, println[run % createImage]);
  266.                field_7.drawLine(2 * run, (out[run % createImage] + out[(run - 1 + createImage) % createImage]) / 2 + 10, 2 * run, (println[run % createImage] + println[(run - 1 + createImage) % createImage]) / 2);
  267.             }
  268.  
  269.             if (drawLine == 0) {
  270.                var1.drawImage(field_5, -move * 2, 0, 20);
  271.                var1.drawImage(field_6, ((Canvas)this).getWidth() - move * 2, 0, 20);
  272.             } else {
  273.                var1.drawImage(field_6, -move * 2, 0, 20);
  274.                var1.drawImage(field_5, ((Canvas)this).getWidth() - move * 2, 0, 20);
  275.             }
  276.  
  277.             if (keyReleased < -2) {
  278.                var1.drawImage(field_10[0], 30, init + 10, 20);
  279.             } else if (-2 <= keyReleased && keyReleased <= 2) {
  280.                var1.drawImage(field_10[1], 30, init + 10, 20);
  281.             } else {
  282.                var1.drawImage(field_10[2], 30, init + 10, 20);
  283.             }
  284.  
  285.             for(getWidth = 0; getWidth < saveHighscore; ++getWidth) {
  286.                if (yield[getWidth] >= 1) {
  287.                   var1.drawImage(field_10[3], (createImage - move + repaint[getWidth]) % createImage * 2, checkInetHighscore[getWidth] + getHeight * 6, 20);
  288.                }
  289.             }
  290.  
  291.             if (init + 8 < out[paint] || println[paint] < init + 14) {
  292.                var1.drawString("Game Over!", ((Canvas)this).getWidth() / 2, ((Canvas)this).getHeight() / 2, 17);
  293.                proc = 2;
  294.             }
  295.  
  296.             for(getWidth = 0; getWidth < saveHighscore; ++getWidth) {
  297.                if (yield[getWidth] >= 1 && paint <= repaint[getWidth] && repaint[getWidth] <= paint + 3 && checkInetHighscore[getWidth] - 10 < init + 10 && init + 10 < checkInetHighscore[getWidth] + 7) {
  298.                   var1.drawString("Game Over!", ((Canvas)this).getWidth() / 2, ((Canvas)this).getHeight() / 2, 17);
  299.                   proc = 2;
  300.                }
  301.             }
  302.  
  303.             var1.drawString("S " + abs + " L " + rand / 2, 0, 0, 20);
  304.             if (setLocalHighscore % 23 - rand / 20 % 6 * 2 == 0) {
  305.                if (0 < rand % 20 && rand % 20 <= 10) {
  306.                   yield[sleep] = (short)(Rand.rand() % (rand / 20 + 1)) % 4 + 1;
  307.                }
  308.  
  309.                if (yield[sleep] <= 3) {
  310.                   repaint[sleep] = run;
  311.                } else if (yield[sleep] == 4) {
  312.                   repaint[sleep] = move;
  313.                }
  314.  
  315.                checkInetHighscore[sleep] = (short)(Rand.rand() % 55) + 10;
  316.                if (sleep < saveHighscore - 1) {
  317.                   ++sleep;
  318.                } else {
  319.                   sleep = 0;
  320.                }
  321.             }
  322.  
  323.             for(getWidth = 0; getWidth < saveHighscore; ++getWidth) {
  324.                if (1 <= yield[getWidth] && yield[getWidth] <= 3 && repaint[getWidth] == move || yield[getWidth] == 4 && (repaint[getWidth] == run || repaint[getWidth] == run - 1)) {
  325.                   yield[getWidth] = 0;
  326.                }
  327.  
  328.                if (yield[getWidth] == 2) {
  329.                   checkInetHighscore[getWidth] = (checkInetHighscore[getWidth] + 2) % 80;
  330.                } else if (yield[getWidth] == 3) {
  331.                   repaint[getWidth] = (repaint[getWidth] - 1 + createImage) % createImage;
  332.                } else if (yield[getWidth] == 4) {
  333.                   repaint[getWidth] = (repaint[getWidth] + 2) % createImage;
  334.                }
  335.             }
  336.  
  337.             ++setLocalHighscore;
  338.             ++abs;
  339.             if (abs % 7 == 0) {
  340.                ++rand;
  341.             }
  342.  
  343.             if (rand % 20 > 9 && toString > 35) {
  344.                --toString;
  345.             } else if (rand % 20 <= 9 && toString < 65) {
  346.                ++toString;
  347.             }
  348.  
  349.             var1.setColor(1);
  350.             var1.drawString(Code, 10, 10, 17);
  351.             break;
  352.          case 2:
  353.             var1.setColor(255, 255, 255);
  354.  
  355.             for(getWidth = 0; getWidth < 5; ++getWidth) {
  356.                var1.drawLine(34, init + 10 + 4, 34 + (short)(Rand.rand() % 150) - 75, init + 10 + 4 + (short)(Rand.rand() % 150) - 75);
  357.             }
  358.  
  359.             var1.drawString("S " + abs + " L " + rand, 0, 0, 20);
  360.             var1.drawString("Game Over!", ((Canvas)this).getWidth() / 2, ((Canvas)this).getHeight() / 2, 17);
  361.             if (this.field_9) {
  362.                var1.drawString("HiScore!!", ((Canvas)this).getWidth() / 2, ((Canvas)this).getHeight() / 2, 33);
  363.             }
  364.  
  365.             ++drawImage;
  366.             if (drawImage > 30) {
  367.                if (this.field_9) {
  368.                   thread_state = false;
  369.                   this.field_0.setLocalHighscore(abs);
  370.                   this.field_0.saveHighscore();
  371.                   this.field_0.checkInetHighscore();
  372.                } else {
  373.                   this.init();
  374.                }
  375.             }
  376.       }
  377.  
  378.    }
  379.  
  380.    public void run() {
  381.       while(true) {
  382.          if (thread_state) {
  383.             this.move();
  384.             ((Canvas)this).repaint();
  385.          }
  386.  
  387.          try {
  388.             Thread.yield();
  389.             Thread.sleep(80L);
  390.          } catch (InterruptedException var2) {
  391.          }
  392.       }
  393.    }
  394.  
  395.    static {
  396.       out = new int[createImage];
  397.       println = new int[createImage];
  398.       saveHighscore = 30;
  399.       checkInetHighscore = new int[saveHighscore];
  400.       repaint = new int[saveHighscore];
  401.       yield = new int[saveHighscore];
  402.       field_3 = new Image[10];
  403.       field_4 = new Image[10];
  404.       field_10 = new Image[10];
  405.       field_11 = new Image[10];
  406.    }
  407. }
  408.